package com.wn.controller;

import com.common.entity.PageParam;
import com.common.entity.Rsp;
import com.common.entity.TravelReviews;
import com.wn.service.TravelReviewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("reviews")
public class TravelReviewsController {
    @Autowired
    TravelReviewsService travelReviewsService;

    @PostMapping("/addOne")
    public Rsp addOne(@RequestBody TravelReviews travelReviews){
        return travelReviewsService.addOne(travelReviews);
    }

    @PostMapping("/del")
    public Rsp delcontent(@RequestBody TravelReviews travelReviews){
        return travelReviewsService.deleteLogical(travelReviews);
    }

    @PostMapping("/updata")
    public Rsp updataContent(@RequestBody TravelReviews travelReviews){
        return travelReviewsService.update(travelReviews);
    }

    @PostMapping("/selectOne")
    public Rsp selectOne(String reviewsId){
        TravelReviews oneById = travelReviewsService.getOneById(reviewsId);
        if (StringUtils.isEmpty(oneById)){
            return Rsp.fail().msg("查找失败");
        }else {
            return Rsp.success(oneById);
        }
    }

    @PostMapping("/searchSomeByPage")
    public Rsp searchSomeByPage(@RequestBody PageParam<TravelReviews> pageParam){
        return Rsp.success(travelReviewsService.searchSomeByPage(pageParam));
    }
}
